﻿using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
/// <summary>
/// 比特转换扩展
/// </summary>
public static class ESF_BitConverterExtend
{
    #region XXXToBytes
    #region bool
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this bool _value)
    {
        return _value.ESF_ToBytes(false);
    }
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this bool _value, bool _hiloSwap)
    {
        return OnESF_ToBytes(_value, (v) => { return BitConverter.GetBytes(v); }, _hiloSwap);
    }
    #endregion

    #region sbyte
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this sbyte _value)
    {
        return _value.ESF_ToBytes(false);
    }
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this sbyte _value, bool _hiloSwap)
    {
        return OnESF_ToBytes(_value, (v) => { return new byte[1] { Convert.ToByte(v) }; }, _hiloSwap);
    }
    #endregion

    #region char
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this char _value)
    {
        return _value.ESF_ToBytes(false);
    }
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this char _value, bool _hiloSwap)
    {
        return OnESF_ToBytes(_value, (v) => { return BitConverter.GetBytes(v); }, _hiloSwap);
    }
    #endregion

    #region short
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this short _value)
    {
        return _value.ESF_ToBytes(false);
    }
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this short _value, bool _hiloSwap)
    {
        return OnESF_ToBytes(_value, (v) => { return BitConverter.GetBytes(v); }, _hiloSwap);
    }
    #endregion

    #region int
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this int _value)
    {
        return _value.ESF_ToBytes(false);
    }
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this int _value, bool _hiloSwap)
    {
        return OnESF_ToBytes(_value, (v) => { return BitConverter.GetBytes(v); }, _hiloSwap);
    }
    #endregion

    #region long
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this long _value)
    {
        return _value.ESF_ToBytes(false);
    }
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this long _value, bool _hiloSwap)
    {
        return OnESF_ToBytes(_value, (v) => { return BitConverter.GetBytes(v); }, _hiloSwap);
    }
    #endregion

    #region float
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this float _value)
    {
        return _value.ESF_ToBytes(false);
    }
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this float _value, bool _hiloSwap)
    {
        return OnESF_ToBytes(_value, (v) => { return BitConverter.GetBytes(v); }, _hiloSwap);
    }
    #endregion

    #region double
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this double _value)
    {
        return _value.ESF_ToBytes(false);
    }
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this double _value, bool _hiloSwap)
    {
        return OnESF_ToBytes(_value, (v) => { return BitConverter.GetBytes(v); }, _hiloSwap);
    }
    #endregion

    #region ushort
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this ushort _value)
    {
        return _value.ESF_ToBytes(false);
    }
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this ushort _value, bool _hiloSwap)
    {
        return OnESF_ToBytes(_value, (v) => { return BitConverter.GetBytes(v); }, _hiloSwap);
    }
    #endregion

    #region uint
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this uint _value)
    {
        return _value.ESF_ToBytes(false);
    }
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this uint _value, bool _hiloSwap)
    {
        return OnESF_ToBytes(_value, (v) => { return BitConverter.GetBytes(v); }, _hiloSwap);
    }
    #endregion

    #region ulong
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this ulong _value)
    {
        return _value.ESF_ToBytes(false);
    }
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this ulong _value, bool _hiloSwap)
    {
        return OnESF_ToBytes(_value, (v) => { return BitConverter.GetBytes(v); }, _hiloSwap);
    }
    #endregion

    #region string
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this string _value)
    {
        return _value.ESF_ToBytes(false);
    }
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this string _value, bool _hiloSwap)
    {
        List<byte> result = new List<byte>();
        byte[] bytes = OnESF_ToBytes(_value, (v) => {
            return Encoding.UTF8.GetBytes(v);
        }, _hiloSwap);
        result.AddRange(bytes.Length.ESF_ToBytes());
        result.AddRange(bytes);
        return result.ToArray();
    }
    #endregion    

    #region Vector2
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this Vector2 _value)
    {
        return _value.ESF_ToBytes(false);
    }
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this Vector2 _value, bool _hiloSwap)
    {
        return _value.OnESF_ToBytes((v) =>
        {
            List<byte> bts = new List<byte>();
            bts.AddRange(v.x.ESF_ToBytes());
            bts.AddRange(v.y.ESF_ToBytes());
            return bts.ToArray();
        }, _hiloSwap);
    }
    #endregion

    #region Vector3
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this Vector3 _value)
    {
        return _value.ESF_ToBytes(false);
    }
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this Vector3 _value, bool _hiloSwap)
    {
        return _value.OnESF_ToBytes((v) =>
        {
            List<byte> bts = new List<byte>();
            bts.AddRange(_value.x.ESF_ToBytes());
            bts.AddRange(_value.y.ESF_ToBytes());
            bts.AddRange(_value.z.ESF_ToBytes());
            return bts.ToArray();
        }, _hiloSwap);
    }
    #endregion

    #region Vector4
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this Vector4 _value)
    {
        return _value.ESF_ToBytes(false);
    }
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_ToBytes(this Vector4 _value, bool _hiloSwap)
    {
        return _value.OnESF_ToBytes((v) =>
        {
            List<byte> bts = new List<byte>();
            bts.AddRange(_value.x.ESF_ToBytes());
            bts.AddRange(_value.y.ESF_ToBytes());
            bts.AddRange(_value.z.ESF_ToBytes());
            bts.AddRange(_value.w.ESF_ToBytes());
            return bts.ToArray();
        }, _hiloSwap);
    }
    #endregion

    #region OnToBytes
    /// <summary>
    /// 获得byte数组
    /// </summary>
    /// <param name="_value">值</param>
    /// <param name="_func">执行函数</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>byte数组</returns>
    static byte[] OnESF_ToBytes<T>(this T _value, Func<T, byte[]> _func, bool _hiloSwap)
    {
        byte[] result = _func(_value);
        if (_hiloSwap)
        {
            result = result.ESF_ToHiloSwap();
        }
        return result;
    }
    #endregion
    #endregion

    #region BytesToXXX

    #region ToBool
    /// <summary>
    /// 获得bool值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <returns>bool值</returns>
    public static bool ESF_ToBool(this byte[] _value)
    {
        return _value.ESF_ToBool(0, false);
    }

    /// <summary>
    /// 获得bool值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>bool值</returns>
    public static bool ESF_ToBool(this byte[] _value, bool _hiloSwap)
    {
        return _value.ESF_ToBool(0, _hiloSwap);
    }

    /// <summary>
    /// 获得bool值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>bool值</returns>
    public static bool ESF_ToBool(this byte[] _value, int _startIndex)
    {
        return _value.ESF_ToBool(_startIndex, false);
    }

    /// <summary>
    /// 获得bool值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>bool值</returns>
    public static bool ESF_ToBool(this byte[] _value, int _startIndex, bool _hiloSwap)
    {
        return _value.ESF_ToBool(ref _startIndex, _hiloSwap);
    }

    /// <summary>
    /// 获得bool值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>bool值</returns>
    public static bool ESF_ToBool(this byte[] _value, ref int _startIndex)
    {
        return _value.ESF_ToBool(ref _startIndex, false);
    }

    /// <summary>
    /// 获得bool值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>bool值</returns>
    public static bool ESF_ToBool(this byte[] _value, ref int _startIndex, bool _hiloSwap)
    {
        if (_hiloSwap)
        {
            _value = _value.ESF_ToHiloSwap();
        }
        bool result = BitConverter.ToBoolean(_value, _startIndex);
        _startIndex += sizeof(bool);
        return result;
    }
    #endregion

    #region ToChar
    /// <summary>
    /// 获得char值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <returns>char值</returns>
    public static char ESF_ToChar(this byte[] _value)
    {
        return _value.ESF_ToChar(0, false);
    }

    /// <summary>
    /// 获得char值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>char值</returns>
    public static char ESF_ToChar(this byte[] _value, bool _hiloSwap)
    {
        return _value.ESF_ToChar(0, _hiloSwap);
    }

    /// <summary>
    /// 获得char值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>char值</returns>
    public static char ESF_ToChar(this byte[] _value, int _startIndex)
    {
        return _value.ESF_ToChar(_startIndex, false);
    }

    /// <summary>
    /// 获得char值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>char值</returns>
    public static char ESF_ToChar(this byte[] _value, int _startIndex, bool _hiloSwap)
    {
        return _value.ESF_ToChar(ref _startIndex, _hiloSwap);
    }

    /// <summary>
    /// 获得char值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>char值</returns>
    public static char ESF_ToChar(this byte[] _value, ref int _startIndex)
    {
        return _value.ESF_ToChar(ref _startIndex, false);
    }

    /// <summary>
    /// 获得char值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>char值</returns>
    public static char ESF_ToChar(this byte[] _value, ref int _startIndex, bool _hiloSwap)
    {
        if (_hiloSwap)
        {
            _value = _value.ESF_ToHiloSwap();
        }
        char result = BitConverter.ToChar(_value, _startIndex);
        _startIndex += sizeof(char);
        return result;
    }
    #endregion

    #region ToByte
    /// <summary>
    /// 获得byte值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <returns>byte值</returns>
    public static byte ESF_ToByte(this byte[] _value)
    {
        return _value.ESF_ToByte(0, false);
    }

    /// <summary>
    /// 获得byte值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>byte值</returns>
    public static byte ESF_ToByte(this byte[] _value, bool _hiloSwap)
    {
        return _value.ESF_ToByte(0, _hiloSwap);
    }

    /// <summary>
    /// 获得byte值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>byte值</returns>
    public static byte ESF_ToByte(this byte[] _value, int _startIndex)
    {
        return _value.ESF_ToByte(_startIndex, false);
    }

    /// <summary>
    /// 获得byte值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>byte值</returns>
    public static byte ESF_ToByte(this byte[] _value, int _startIndex, bool _hiloSwap)
    {
        return _value.ESF_ToByte(ref _startIndex, _hiloSwap);
    }

    /// <summary>
    /// 获得byte值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>byte值</returns>
    public static byte ESF_ToByte(this byte[] _value, ref int _startIndex)
    {
        return _value.ESF_ToByte(ref _startIndex, false);
    }

    /// <summary>
    /// 获得byte值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>byte值</returns>
    public static byte ESF_ToByte(this byte[] _value, ref int _startIndex, bool _hiloSwap)
    {
        if (_hiloSwap)
        {
            _value = _value.ESF_ToHiloSwap();
        }
        byte result = _value[_startIndex];
        _startIndex += sizeof(byte);
        return result;
    }
    #endregion

    #region ToInt16
    /// <summary>
    /// 获得short值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <returns>short值</returns>
    public static short ESF_ToInt16(this byte[] _value)
    {
        return _value.ESF_ToInt16(0, false);
    }

    /// <summary>
    /// 获得short值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>short值</returns>
    public static short ESF_ToInt16(this byte[] _value, bool _hiloSwap)
    {
        return _value.ESF_ToInt16(0, _hiloSwap);
    }

    /// <summary>
    /// 获得short值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>short值</returns>
    public static short ESF_ToInt16(this byte[] _value, int _startIndex)
    {
        return _value.ESF_ToInt16(_startIndex, false);
    }

    /// <summary>
    /// 获得short值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>short值</returns>
    public static short ESF_ToInt16(this byte[] _value, int _startIndex, bool _hiloSwap)
    {
        return _value.ESF_ToInt16(ref _startIndex, _hiloSwap);
    }

    /// <summary>
    /// 获得short值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>short值</returns>
    public static short ESF_ToInt16(this byte[] _value, ref int _startIndex)
    {
        return _value.ESF_ToInt16(ref _startIndex, false);
    }

    /// <summary>
    /// 获得short值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>short值</returns>
    public static short ESF_ToInt16(this byte[] _value, ref int _startIndex, bool _hiloSwap)
    {
        if (_hiloSwap)
        {
            _value = _value.ESF_ToHiloSwap(); 
        }        
        short result = BitConverter.ToInt16(_value, _startIndex);
        _startIndex += sizeof(short);
        return result;
    }
    #endregion

    #region ToInt32
    /// <summary>
    /// 获得int值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <returns>int值</returns>
    public static int ESF_ToInt32(this byte[] _value)
    {
        return _value.ESF_ToInt32(0, false);
    }

    /// <summary>
    /// 获得int值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>int值</returns>
    public static int ESF_ToInt32(this byte[] _value, bool _hiloSwap)
    {
        return _value.ESF_ToInt32(0, _hiloSwap);
    }

    /// <summary>
    /// 获得int值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>int值</returns>
    public static int ESF_ToInt32(this byte[] _value, int _startIndex)
    {
        return _value.ESF_ToInt32(_startIndex, false);
    }

    /// <summary>
    /// 获得int值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>int值</returns>
    public static int ESF_ToInt32(this byte[] _value, int _startIndex, bool _hiloSwap)
    {
        return _value.ESF_ToInt32(ref _startIndex, _hiloSwap);
    }

    /// <summary>
    /// 获得int值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>int值</returns>
    public static int ESF_ToInt32(this byte[] _value, ref int _startIndex)
    {
        return _value.ESF_ToInt32(ref _startIndex, false);
    }

    /// <summary>
    /// 获得int值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>int值</returns>
    public static int ESF_ToInt32(this byte[] _value, ref int _startIndex, bool _hiloSwap)
    {
        if (_hiloSwap)
        {
            _value = _value.ESF_ToHiloSwap();
        }        
        int result = BitConverter.ToInt32(_value, _startIndex);
        _startIndex += sizeof(int);
        return result;
    }
    #endregion

    #region ToInt64
    /// <summary>
    /// 获得long值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <returns>long值</returns>
    public static long ESF_ToInt64(this byte[] _value)
    {
        return _value.ESF_ToInt64(0, false);
    }

    /// <summary>
    /// 获得long值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>long值</returns>
    public static long ESF_ToInt64(this byte[] _value, bool _hiloSwap)
    {
        return _value.ESF_ToInt64(0, _hiloSwap);
    }

    /// <summary>
    /// 获得long值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>long值</returns>
    public static long ESF_ToInt64(this byte[] _value, int _startIndex)
    {
        return _value.ESF_ToInt64(_startIndex, false);
    }

    /// <summary>
    /// 获得long值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>long值</returns>
    public static long ESF_ToInt64(this byte[] _value, int _startIndex, bool _hiloSwap)
    {
        return _value.ESF_ToInt64(ref _startIndex, _hiloSwap);
    }

    /// <summary>
    /// 获得long值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>long值</returns>
    public static long ESF_ToInt64(this byte[] _value, ref int _startIndex)
    {
        return _value.ESF_ToInt64(ref _startIndex, false);
    }

    /// <summary>
    /// 获得long值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>long值</returns>
    public static long ESF_ToInt64(this byte[] _value, ref int _startIndex, bool _hiloSwap)
    {
        if (_hiloSwap)
        {
            _value = _value.ESF_ToHiloSwap();
        }
        long result = BitConverter.ToInt64(_value, _startIndex);
        _startIndex += sizeof(long);
        return result;
    }
    #endregion

    #region ToFloat
    /// <summary>
    /// 获得float值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <returns>float值</returns>
    public static float ESF_ToFloat(this byte[] _value)
    {
        return _value.ESF_ToFloat(0, false);
    }

    /// <summary>
    /// 获得float值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>float值</returns>
    public static float ESF_ToFloat(this byte[] _value, bool _hiloSwap)
    {
        return _value.ESF_ToFloat(0, _hiloSwap);
    }

    /// <summary>
    /// 获得float值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>float值</returns>
    public static float ESF_ToFloat(this byte[] _value, int _startIndex)
    {
        return _value.ESF_ToFloat(_startIndex, false);
    }

    /// <summary>
    /// 获得float值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>float值</returns>
    public static float ESF_ToFloat(this byte[] _value, int _startIndex, bool _hiloSwap)
    {
        return _value.ESF_ToFloat(ref _startIndex, _hiloSwap);
    }

    /// <summary>
    /// 获得float值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>float值</returns>
    public static float ESF_ToFloat(this byte[] _value, ref int _startIndex)
    {
        return _value.ESF_ToFloat(ref _startIndex, false);
    }

    /// <summary>
    /// 获得float值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>float值</returns>
    public static float ESF_ToFloat(this byte[] _value, ref int _startIndex, bool _hiloSwap)
    {
        if (_hiloSwap)
        {
            _value = _value.ESF_ToHiloSwap();
        }
        float result = BitConverter.ToSingle(_value, _startIndex);
        _startIndex += sizeof(float);
        return result;
    }
    #endregion

    #region ToDouble
    /// <summary>
    /// 获得double值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <returns>double值</returns>
    public static double ESF_ToDouble(this byte[] _value)
    {
        return _value.ESF_ToDouble(0, false);
    }

    /// <summary>
    /// 获得double值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>double值</returns>
    public static double ESF_ToDouble(this byte[] _value, bool _hiloSwap)
    {
        return _value.ESF_ToDouble(0, _hiloSwap);
    }

    /// <summary>
    /// 获得double值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>double值</returns>
    public static double ESF_ToDouble(this byte[] _value, int _startIndex)
    {
        return _value.ESF_ToDouble(_startIndex, false);
    }

    /// <summary>
    /// 获得double值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>double值</returns>
    public static double ESF_ToDouble(this byte[] _value, int _startIndex, bool _hiloSwap)
    {
        return _value.ESF_ToDouble(ref _startIndex, _hiloSwap);
    }

    /// <summary>
    /// 获得double值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>double值</returns>
    public static double ESF_ToDouble(this byte[] _value, ref int _startIndex)
    {
        return _value.ESF_ToDouble(ref _startIndex, false);
    }

    /// <summary>
    /// 获得double值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>double值</returns>
    public static double ESF_ToDouble(this byte[] _value, ref int _startIndex, bool _hiloSwap)
    {
        if (_hiloSwap)
        {
            _value = _value.ESF_ToHiloSwap();
        }
        double result = BitConverter.ToDouble(_value, _startIndex);
        _startIndex += sizeof(double);
        return result;
    }
    #endregion

    #region ToUInt3216
    /// <summary>
    /// 获得ushort值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <returns>ushort值</returns>
    public static ushort ESF_ToUInt3216(this byte[] _value)
    {
        return _value.ESF_ToUInt3216(0, false);
    }

    /// <summary>
    /// 获得ushort值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>ushort值</returns>
    public static ushort ESF_ToUInt3216(this byte[] _value, bool _hiloSwap)
    {
        return _value.ESF_ToUInt3216(0, _hiloSwap);
    }

    /// <summary>
    /// 获得ushort值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>ushort值</returns>
    public static ushort ESF_ToUInt3216(this byte[] _value, int _startIndex)
    {
        return _value.ESF_ToUInt3216(_startIndex, false);
    }

    /// <summary>
    /// 获得ushort值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>ushort值</returns>
    public static ushort ESF_ToUInt3216(this byte[] _value, int _startIndex, bool _hiloSwap)
    {
        return _value.ESF_ToUInt3216(ref _startIndex, _hiloSwap);
    }

    /// <summary>
    /// 获得ushort值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>ushort值</returns>
    public static ushort ESF_ToUInt3216(this byte[] _value, ref int _startIndex)
    {
        return _value.ESF_ToUInt3216(ref _startIndex, false);
    }

    /// <summary>
    /// 获得ushort值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>ushort值</returns>
    public static ushort ESF_ToUInt3216(this byte[] _value, ref int _startIndex, bool _hiloSwap)
    {
        if (_hiloSwap)
        {
            _value = _value.ESF_ToHiloSwap();
        }
        ushort result = BitConverter.ToUInt16(_value, _startIndex);
        _startIndex += sizeof(ushort);
        return result;
    }
    #endregion

    #region ToUInt32
    /// <summary>
    /// 获得uint值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <returns>uint值</returns>
    public static uint ESF_ToUInt32(this byte[] _value)
    {
        return _value.ESF_ToUInt32(0, false);
    }

    /// <summary>
    /// 获得uint值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>uint值</returns>
    public static uint ESF_ToUInt32(this byte[] _value, bool _hiloSwap)
    {
        return _value.ESF_ToUInt32(0, _hiloSwap);
    }

    /// <summary>
    /// 获得uint值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>uint值</returns>
    public static uint ESF_ToUInt32(this byte[] _value, int _startIndex)
    {
        return _value.ESF_ToUInt32(_startIndex, false);
    }

    /// <summary>
    /// 获得uint值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>uint值</returns>
    public static uint ESF_ToUInt32(this byte[] _value, int _startIndex, bool _hiloSwap)
    {
        return _value.ESF_ToUInt32(ref _startIndex, _hiloSwap);
    }

    /// <summary>
    /// 获得uint值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>uint值</returns>
    public static uint ESF_ToUInt32(this byte[] _value, ref int _startIndex)
    {
        return _value.ESF_ToUInt32(ref _startIndex, false);
    }

    /// <summary>
    /// 获得uint值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>uint值</returns>
    public static uint ESF_ToUInt32(this byte[] _value, ref int _startIndex, bool _hiloSwap)
    {
        if (_hiloSwap)
        {
            _value = _value.ESF_ToHiloSwap();
        }
        uint result = BitConverter.ToUInt32(_value, _startIndex);
        _startIndex += sizeof(uint);
        return result;
    }
    #endregion

    #region ToUInt64
    /// <summary>
    /// 获得ulong值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <returns>ulong值</returns>
    public static ulong ESF_ToUInt64(this byte[] _value)
    {
        return _value.ESF_ToUInt64(0, false);
    }

    /// <summary>
    /// 获得ulong值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>ulong值</returns>
    public static ulong ESF_ToUInt64(this byte[] _value, bool _hiloSwap)
    {
        return _value.ESF_ToUInt64(0, _hiloSwap);
    }

    /// <summary>
    /// 获得ulong值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>ulong值</returns>
    public static ulong ESF_ToUInt64(this byte[] _value, int _startIndex)
    {
        return _value.ESF_ToUInt64(_startIndex, false);
    }

    /// <summary>
    /// 获得ulong值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>ulong值</returns>
    public static ulong ESF_ToUInt64(this byte[] _value, int _startIndex, bool _hiloSwap)
    {
        return _value.ESF_ToUInt64(ref _startIndex, _hiloSwap);
    }

    /// <summary>
    /// 获得ulong值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>ulong值</returns>
    public static ulong ESF_ToUInt64(this byte[] _value, ref int _startIndex)
    {
        return _value.ESF_ToUInt64(ref _startIndex, false);
    }

    /// <summary>
    /// 获得ulong值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>ulong值</returns>
    public static ulong ESF_ToUInt64(this byte[] _value, ref int _startIndex, bool _hiloSwap)
    {
        if (_hiloSwap)
        {
            _value = _value.ESF_ToHiloSwap();
        }
        ulong result = BitConverter.ToUInt64(_value, _startIndex);
        _startIndex += sizeof(ulong);
        return result;
    }
    #endregion

    #region BytesToString
    /// <summary>
    /// 获得string值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <returns>string值</returns>
    public static string ESF_BytesToString(this byte[] _value)
    {
        return _value.ESF_BytesToString(0, false);
    }

    /// <summary>
    /// 获得string值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>string值</returns>
    public static string ESF_BytesToString(this byte[] _value, bool _hiloSwap)
    {
        return _value.ESF_BytesToString(0, _hiloSwap);
    }

    /// <summary>
    /// 获得string值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>string值</returns>
    public static string ESF_BytesToString(this byte[] _value, int _startIndex)
    {
        return _value.ESF_BytesToString(_startIndex, false);
    }

    /// <summary>
    /// 获得string值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>string值</returns>
    public static string ESF_BytesToString(this byte[] _value, int _startIndex, bool _hiloSwap)
    {
        return _value.ESF_BytesToString(ref _startIndex, _hiloSwap);
    }

    /// <summary>
    /// 获得string值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>string值</returns>
    public static string ESF_BytesToString(this byte[] _value, ref int _startIndex)
    {
        return _value.ESF_BytesToString(ref _startIndex, false);
    }

    /// <summary>
    /// 获得string值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>string值</returns>
    public static string ESF_BytesToString(this byte[] _value, ref int _startIndex, bool _hiloSwap)
    {
        int size = _value.ESF_ToInt32(ref _startIndex, _hiloSwap);
        byte[] result = ESF_CopyBuffer(_value, _startIndex, size, _hiloSwap);
        _startIndex += size;
        return Encoding.UTF8.GetString(result);
    }
    #endregion

    #region ToVector2
    /// <summary>
    /// 获得Vector2值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <returns>Vector2值</returns>
    public static Vector2 ESF_ToVector2(this byte[] _value)
    {
        return _value.ESF_ToVector2(0, false);
    }

    /// <summary>
    /// 获得Vector2值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>Vector2值</returns>
    public static Vector2 ESF_ToVector2(this byte[] _value, bool _hiloSwap)
    {
        return _value.ESF_ToVector2(0, _hiloSwap);
    }

    /// <summary>
    /// 获得Vector2值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>Vector2值</returns>
    public static Vector2 ESF_ToVector2(this byte[] _value, int _startIndex)
    {
        return _value.ESF_ToVector2(_startIndex, false);
    }

    /// <summary>
    /// 获得Vector2值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>Vector2值</returns>
    public static Vector2 ESF_ToVector2(this byte[] _value, int _startIndex, bool _hiloSwap)
    {
        return _value.ESF_ToVector2(ref _startIndex, _hiloSwap);
    }

    /// <summary>
    /// 获得Vector2值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>Vector2值</returns>
    public static Vector2 ESF_ToVector2(this byte[] _value, ref int _startIndex)
    {
        return _value.ESF_ToVector2(ref _startIndex, false);
    }

    /// <summary>
    /// 获得Vector2值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>Vector2值</returns>
    public static Vector2 ESF_ToVector2(this byte[] _value, ref int _startIndex, bool _hiloSwap)
    {
        if (_hiloSwap)
        {
            _value = _value.ESF_ToHiloSwap();
        }
        Vector2 result = Vector2.zero;
        result.x = BitConverter.ToSingle(_value, _startIndex);
        _startIndex += sizeof(float);
        result.y = BitConverter.ToSingle(_value, _startIndex);
        _startIndex += sizeof(float);
        return result;
    }
    #endregion

    #region ToVector3
    /// <summary>
    /// 获得Vector3值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <returns>Vector3值</returns>
    public static Vector3 ESF_ToVector3(this byte[] _value)
    {
        return _value.ESF_ToVector3(0, false);
    }

    /// <summary>
    /// 获得Vector3值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>Vector3值</returns>
    public static Vector3 ESF_ToVector3(this byte[] _value, bool _hiloSwap)
    {
        return _value.ESF_ToVector3(0, _hiloSwap);
    }

    /// <summary>
    /// 获得Vector3值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>Vector3值</returns>
    public static Vector3 ESF_ToVector3(this byte[] _value, int _startIndex)
    {
        return _value.ESF_ToVector3(_startIndex, false);
    }

    /// <summary>
    /// 获得Vector3值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>Vector3值</returns>
    public static Vector3 ESF_ToVector3(this byte[] _value, int _startIndex, bool _hiloSwap)
    {
        return _value.ESF_ToVector3(ref _startIndex, _hiloSwap);
    }

    /// <summary>
    /// 获得Vector3值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>Vector3值</returns>
    public static Vector3 ESF_ToVector3(this byte[] _value, ref int _startIndex)
    {
        return _value.ESF_ToVector3(ref _startIndex, false);
    }

    /// <summary>
    /// 获得Vector3值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>Vector3值</returns>
    public static Vector3 ESF_ToVector3(this byte[] _value, ref int _startIndex, bool _hiloSwap)
    {
        if (_hiloSwap)
        {
            _value = _value.ESF_ToHiloSwap();
        }
        Vector3 result = Vector3.zero;
        result.x = BitConverter.ToSingle(_value, _startIndex);
        _startIndex += sizeof(float);
        result.y = BitConverter.ToSingle(_value, _startIndex);
        _startIndex += sizeof(float);
        result.z = BitConverter.ToSingle(_value, _startIndex);
        _startIndex += sizeof(float);
        return result;
    }
    #endregion

    #region ToVector4
    /// <summary>
    /// 获得Vector4值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <returns>Vector4值</returns>
    public static Vector4 ESF_ToVector4(this byte[] _value)
    {
        return _value.ESF_ToVector4(0, false);
    }

    /// <summary>
    /// 获得Vector4值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>Vector4值</returns>
    public static Vector4 ESF_ToVector4(this byte[] _value, bool _hiloSwap)
    {
        return _value.ESF_ToVector4(0, _hiloSwap);
    }

    /// <summary>
    /// 获得Vector4值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>Vector4值</returns>
    public static Vector4 ESF_ToVector4(this byte[] _value, int _startIndex)
    {
        return _value.ESF_ToVector4(_startIndex, false);
    }

    /// <summary>
    /// 获得Vector4值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>Vector4值</returns>
    public static Vector4 ESF_ToVector4(this byte[] _value, int _startIndex, bool _hiloSwap)
    {
        return _value.ESF_ToVector4(ref _startIndex, _hiloSwap);
    }

    /// <summary>
    /// 获得Vector4值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <returns>Vector4值</returns>
    public static Vector4 ESF_ToVector4(this byte[] _value, ref int _startIndex)
    {
        return _value.ESF_ToVector4(ref _startIndex, false);
    }

    /// <summary>
    /// 获得Vector4值
    /// </summary>
    /// <param name="_value">byte数组源</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>Vector4值</returns>
    public static Vector4 ESF_ToVector4(this byte[] _value, ref int _startIndex, bool _hiloSwap)
    {
        if (_hiloSwap)
        {
            _value = _value.ESF_ToHiloSwap();
        }
        Vector4 result = Vector4.zero;
        result.x = BitConverter.ToSingle(_value, _startIndex);
        _startIndex += sizeof(float);
        result.y = BitConverter.ToSingle(_value, _startIndex);
        _startIndex += sizeof(float);
        result.z = BitConverter.ToSingle(_value, _startIndex);
        _startIndex += sizeof(float);
        result.w = BitConverter.ToSingle(_value, _startIndex);
        _startIndex += sizeof(float);
        return result;
    }
    #endregion
    #endregion

    #region CopyBuffer
    /// <summary>
    /// 复制数据缓存
    /// </summary>
    /// <param name="_source">源数据</param>
    /// <param name="_startIndex">起始位置</param>
    /// <param name="_length">长度</param>
    /// <param name="_hiloSwap">是否高低位互换</param>
    /// <returns>byte数组</returns>
    public static byte[] ESF_CopyBuffer(this byte[] _source, long _startIndex, long _length, bool _hiloSwap)
    {
        byte[] result = new byte[_length];
        Array.Copy(_source, _startIndex, result, 0, _length);
        if (_length > 0 && _hiloSwap)
        {
            result = result.ESF_ToHiloSwap();
        }
        return result;
    }
    #endregion
}